# --*-- coding=utf-8 --*--
"""
日志模块封装类
"""
from logging import Formatter, INFO, getLogger, StreamHandler
from logging.handlers import TimedRotatingFileHandler
from auto_test.config import BaseConfig
from auto_test.lib.file_util import get_abs_path
import sys


def _get_my_logger():
    myLogger = getLogger()
    myLogger.setLevel(INFO)
    sh = StreamHandler(sys.stdout)
    fmt = Formatter('%(asctime)s[%(thread)d][%(levelname)s]%(message)s')
    sh.setFormatter(fmt)
    sh.setLevel(INFO)
    myLogger.addHandler(sh)
    trsh = TimedRotatingFileHandler(get_abs_path(BaseConfig.TEST_LOG_DIR), when='H', backupCount=5)
    trsh.setFormatter(fmt)
    trsh.setLevel(INFO)
    trsh.suffix = '%Y_%m_%d_%H.log'
    myLogger.addHandler(trsh)
    return myLogger


logger = _get_my_logger()


def info(msg):
    logger.info(msg)


def debug(msg):
    logger.debug(msg)


def warning(msg):
    logger.warning(msg)


def error(msg):
    logger.error(msg, exc_info=True)
